<template>
    <view class="goods-item">
      <!-- 左侧图片 -->
      <view class="left-box">
        <!-- 选框 默认选中-->
        <radio @click="updateSelectState" v-if="showRadio" :checked="goods.goods_state"  color="#C00000"></radio>
        <image class="goods-img" :src="gooods.goods_small_logo" mode=""></image>
      </view>
      <!-- 右侧内容 -->
      <view class="right-box">
        <!-- 商品标题 -->
        <view class="goods-title">{{goods.goods_name}}</view>
        <!-- 价格 -->
        <view class="right-info">
          <view class="goods-price">¥{{goods.goods_price | toFixed}}</view>
          <uni-number-box v-if="showNum" @change="bindChange" :value="goods.goods_count" :min="1"></uni-number-box>
        </view>
      </view>
    </view>
</template>

<script>
  export default {
    name:"my-goods",
    props: {
      goods: {
        type: Object,
        default: {}
      },
      showRadio: {
        type: Boolean,
        default: false
      },
      showNum: {
        stype: Boolean,
        default: false
      }
    },
    data() {
      return {
        
      };
    },
    methods: {
      updateSelectState() {
        this.$emit('radio-change', {
          // 商品的 Id
                goods_id: this.goods.goods_id,
                // 商品最新的勾选状态
                goods_state: !this.goods.goods_state
        })
      },
      //监听组件数量的变化
      bindChange (newValue) {
        this.$emit('num-change', {
          goods_id: this.goods.goods_id,
          goods_count: +newValue
        })
      },
    },
    
    //过滤器， 保留两位小数
    filters: {
      //把数字处理为带两位小数的数字
      toFixed(num) {
        return Number(num).toFixed(2)
        
      }
    }
  }
</script>

<style lang="scss">
  .goods-item {
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #f0f0f0;
    .left-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-right: 5px;
      .goods-img {
        display: block;
        width: 100px;
        height: 100px;
        border: 1px solid red;
      }
    }
    .right-box {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;
      .goods-title {
        font-size: 12px;
      }
      .right-info {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .goods-price {
          font-size: 16px;
          color: #c00000;
        }
      }
    }
  }

</style>